<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组</title>
</head>
<body>

</body>
<script>
    let arr = [111,3424,45,5446,65];
    let arr2 = ["就这","张三","王五","赵六"];
    //拼接数组，返回新数组
    let concat = arr.concat(arr2);
    console.log(concat);
    //排序。默认按照字典排序，数字大小排序需要自己写比值函数
    let sort = arr.sort();
    console.log(sort);
    //从小到大排序
    let sort1 = arr.sort(function (a, b) {
        return a-b;
    });
    console.log(sort1);
    //数组的截取，指定起始位置和指定结束位置
    let slice = arr.slice(2,4);
    console.log(slice);
    //第一个参数为索引，第二个参数删除为索引开始的数组长度，后面则为在索引位置添加的元素，返回被删除的元素数组
    let splice = arr2.splice(2,2,"赵七","大郎");
    console.log(splice);
    console.log(arr2);
    //向数组后面追加元素,返回新数组的长度
    let push = arr2.push("aaa","bbb");
    console.log(push);
    console.log(arr2);
    //删除最后一个元素，并返回弹出的值
    let pop = arr2.pop();
    console.log(pop);
    console.log(arr2);
    //将数组拼接成字符串返回,默认用逗号分割
    let s = arr.join();
    console.log(s);
    //指定分隔符分割
    let s1 = arr.join("*");
    console.log(s1);
    //删除首个元素并返回
    let shift = arr.shift();
    console.log(arr);
    console.log(shift);
    //返回数组字符串，逗号分割
    let string = arr.toString();
    console.log(string);
    //数组反转
    arr.reverse();
    console.log(arr);
    //在每个元素上运行此方法
    //求和
    let reduce = arr.reduce(function (total, value) {
        return total+value;
    });
    console.log(reduce);

</script>
</html>